/**
 * 
 */
package edu.wpi.cs509.messages;

/**
 * This class implements rxExecute(). rxExecute calls getReplyMsg from the 
 * derived class, and sends that reply automatically. 
 * @author sparadis
 *
 */
public abstract class MsgAutoReply extends MsgBc {
	/**
	 * serializable version number
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor, empty so far.
	 */
	public MsgAutoReply() {
	}
	
	/**
	 * Send the reply message from doExecuteAndGetReply function. Only do 
	 * this if the returned msg is not null. 
	 */
	public void rxExecute() {
		MsgBc msg = doExecuteAndGetReply();
		if (msg != null) sendReply(msg);
	}
	
	/**
	 * This function should execute the necessary client/server function, 
	 * then create and return the reply message.
	 * @return MsgBc - the replay message for the executed message. 
	 */
	abstract public MsgBc doExecuteAndGetReply();
}
